<?php
ob_start();
session_start();

include("conf/config.php");
include("conf/database.php");
include("conf/tools.php");

$curTime=getIndianDateTime();

foreach($_POST as $key => $value) { $arr_data[$key]=$value;}

$arr_data["gender"]=$arr_data["rbGender"];
if($arr_data["reg_state"]=="Other") $arr_data["reg_state"]=$arr_data["reg_state_other"];
$arr_data["telephone_no"]=$arr_data["telephone_number"];
$arr_data["mobile_no"]=$arr_data["cell_number"];
$arr_data["alternate_email_id"]=$arr_data["alternate_email"];
$arr_data["email_id"]=$arr_data["email_address"];

$arr_data["rec_status"]="1";
$arr_data["reg_type"]=$arr_data["ddlRegType"];
if($arr_data["reg_type"]=="") $arr_data["reg_type"]="1";
if($arr_data["are_you_bk"]==0) $arr_data["aloukik_dob"]='';

if($arr_data["reg_state"]=="Other") $arr_data["reg_state"]=$_POST["reg_country_other"];
if($arr_data["reg_country"]=="Other") $arr_data["reg_country"]=$_POST["reg_country_other"];
if($arr_data["reg_state1"]=="Other") $arr_data["reg_state1"]=$_POST["reg_country_other1"];
if($arr_data["reg_country1"]=="Other") $arr_data["reg_country1"]=$_POST["reg_country_other1"];

if($arr_data["edu_qual"]=="Other") $arr_data["edu_qual"]=$_POST["edu_qual_other"];
if($arr_data["technical_specifications"]=="Other") $arr_data["technical_specifications"]=$_POST["technical_specifications_other"];


foreach($arr_data as $key => $value) { $arr_data[$key]=addslashes($value); }

$isHack=false;
$ip=$_SERVER['REMOTE_ADDR'];
$hackersIp=Array("193.203.48.16");


//captcha
if($arr_data["telephone_no"]=="123456" || $arr_data["dob"]=="0000-00-00" || $arr_data["dob"]=="1899-11-30") $isHack=true;
if($_SESSION['randomnr2']!=md5($_POST["captcha_code"])) {
	$_SESSION["form-data"]=$_POST;
	$isHack=true;
}else{
	unset($_SESSION["form-data"]);
}
if(in_array($ip,$hackersIp)) $isHack=true;


if($isHack){
	writeLog($arr_data["full_name"]." Hacker Detected.");
	header("location:register.php?m=2");
	exit;
}


$memberId=insert_qry("bkitc_profiles",$arr_data);

$member_code=formatMemberCode($memberId);
$_SESSION["member_code"]=$member_code;
$arr_data1["reg_password"]=generatePassword($member_code);


update_qry("bkitc_profiles",$arr_data1,"registrant_id=".$memberId);

$toEmailId=$arr_data["email_id"];

$target_path = "images/photos/";
$target_path1 = "data/resumes/";

$actual_path=$target_path . $memberId . "/";
if(!is_dir($target_path)) mkdir($target_path);
if(!is_dir($actual_path)) mkdir($actual_path);

$actual_path1=$target_path1 . $memberId . "/";
if(!is_dir($target_path1)) mkdir($target_path1);
if(!is_dir($actual_path1)) mkdir($actual_path1);

$target_path = $target_path . basename( $_FILES['file_photo']['name']); 
$target_path1 = $target_path1 . basename( $_FILES['file_resume']['name']); 

$arrInfo=array();
if(move_uploaded_file($_FILES['file_photo']['tmp_name'],$actual_path.$_FILES['file_photo']['name'])) {

	$arrInfo["photo_filename"]=$_FILES['file_photo']['name'];
	
	update_qry("bkitc_profiles",$arrInfo," registrant_id=".$memberId);

} 

$arrInfo=array();
if(move_uploaded_file($_FILES['file_resume']['tmp_name'],$actual_path1.$_FILES['file_resume']['name'])) {

	$arrInfo["resume_filename"]=$_FILES['file_resume']['name'];
	$arrInfo["resume_uploaded"]=$curTime;
	update_qry("bkitc_profiles",$arrInfo," registrant_id=".$memberId);

} 



qry_data("update bkitc_profiles set submission_date='".$curTime."' where registrant_id=".$memberId);

if($toEmailId!="") send_member_email($toEmailId,$memberId,"");

writeLog($arr_data["full_name"]." become a new member.");

header("location:user_thank.php");
?>

